package com.erlang.spring.controller;

import com.erlang.spring.dao.AccountDao;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @Description：
 */
public class ClientController {


  /**
   * ApplicationContext:spring-IOC容器
   * ClassPathXmlApplicationContext：容器实现类，加载配置文件
   * applicationContext.getBean：获得容器中的bean对象
   */
  @Test
  public void saveAccount() {

    /**
     * Spring-IOC容器：ApplicationContext
     * 构建方式：通过ClassPathXmlApplicationContext加载配置文件
     * 使用bean:getBean
     */
    ApplicationContext applicationContext = new ClassPathXmlApplicationContext("bean.xml");
    AccountDao accountDaoA = (AccountDao) applicationContext.getBean("accountDao");
    AccountDao accountDaoB = (AccountDao) applicationContext.getBean("accountDao");

    System.out.println("accountDaoA的内存地址："+accountDaoA.hashCode());
    System.out.println("accountDaoB的内存地址："+accountDaoB.hashCode());

  }

}
